package com.alex.xmlyfm.entities.discoverrecommend;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.LinkedList;
import java.util.List;

/**
 * Created by
 * Author: alex
 * Email:
 * Date: 15-10-21.
 */
public class DiscoverRecommendAlbums extends DiscoverRecommendItem{
    private int ret;

    /**
     * 推荐的专辑
     */
    private List<AlbumRecommend> albumRecommends;

    public List<AlbumRecommend> getAlbumRecommends() {
        return albumRecommends;
    }

    public void parseJSON(JSONObject json) throws JSONException {

        if (json != null) {
            // 调用父类解析，解析父类需要使用的数据
            super.parseJSON(json);
        }
        ret = json.optInt("ret");
        JSONArray array = json.getJSONArray("list");
        int len = array.length();
        albumRecommends = new LinkedList<>();
        if (len > 0 ){
            for (int i = 0; i < len; i++) {
                // 解析内部的专辑推荐
                JSONObject jsonObject = array.getJSONObject(i);
                AlbumRecommend album = new AlbumRecommend();
                album.parseJSON(jsonObject);
                albumRecommends.add(album);
            }
        }
    }

}
